<?php
/**
 * ReportApi
 * PHP version 5
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */

/**
 * Brand Metrics
 *
 * Brand Metrics provides a new measurement solution that quantifies opportunities for your brand at each stage of the customer journey on Amazon, and helps brands understand the value of different shopping engagements that impact stages of that journey. You can now access Awareness and Consideration indices that compare your performance to peers using models predictive of consideration and sales. Brand Metrics quantifies the number of customers in the awareness and consideration marketing funnel stages and is built at scale to measure all shopping engagements with your brand on Amazon, not just ad-attributed engagements. Additionally, BM breaks out key shopping engagements at each stage of the shopping journey, along with the Return on Engagement, so you can measure the historical sales following a consideration event or purchase.
 *
 * OpenAPI spec version: 3.0
 * 
 * Generated by:https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api.git
 * AmazonAdvertisingApi Codegen version: 3.0.51
 */
/**
 * NOTE: This class is auto generated by the AmazonAdvertisingApi code generator program.
 *https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 * Do not edit the class manually.
 */

namespace AmazonAdvertisingApi\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use AmazonAdvertisingApi\ApiException;
use AmazonAdvertisingApi\Configuration;
use AmazonAdvertisingApi\HeaderSelector;
use AmazonAdvertisingApi\ObjectSerializer;

/**
 * ReportApi Class Doc Comment
 *
 * @category Class
 * @package  AmazonAdvertisingApi
 * @author   vv_guo
 * @link    https://gitee.com/HuaLiLiDeDiDiao/amazon-advertising-api
 */
class ReportApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation generateBrandMetricsReport
     *
     * Generate Brand Metrics Report. Each response record will include the following dimensional fields (in addition to the requested metrics) brand Namecategory, TreeNamecategory, HierarchylookbackPeriod, metricsComputationDate
     *
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     * @param  \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportRequest $body Create request body to generate the Brand Metrics Report (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportResponse
     */
    public function generateBrandMetricsReport($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body = null)
    {
        list($response) = $this->generateBrandMetricsReportWithHttpInfo($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body);
        return $response;
    }

    /**
     * Operation generateBrandMetricsReportWithHttpInfo
     *
     * Generate Brand Metrics Report. Each response record will include the following dimensional fields (in addition to the requested metrics) brand Namecategory, TreeNamecategory, HierarchylookbackPeriod, metricsComputationDate
     *
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     * @param  \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportRequest $body Create request body to generate the Brand Metrics Report (optional)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function generateBrandMetricsReportWithHttpInfo($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\BrandMetricsGenerateReportResponse';
        $request = $this->generateBrandMetricsReportRequest($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsGenerateReportResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 424:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation generateBrandMetricsReportAsync
     *
     * Generate Brand Metrics Report. Each response record will include the following dimensional fields (in addition to the requested metrics) brand Namecategory, TreeNamecategory, HierarchylookbackPeriod, metricsComputationDate
     *
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     * @param  \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportRequest $body Create request body to generate the Brand Metrics Report (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function generateBrandMetricsReportAsync($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body = null)
    {
        return $this->generateBrandMetricsReportAsyncWithHttpInfo($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation generateBrandMetricsReportAsyncWithHttpInfo
     *
     * Generate Brand Metrics Report. Each response record will include the following dimensional fields (in addition to the requested metrics) brand Namecategory, TreeNamecategory, HierarchylookbackPeriod, metricsComputationDate
     *
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     * @param  \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportRequest $body Create request body to generate the Brand Metrics Report (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function generateBrandMetricsReportAsyncWithHttpInfo($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body = null)
    {
        $returnType = '\AmazonAdvertisingApi\Model\BrandMetricsGenerateReportResponse';
        $request = $this->generateBrandMetricsReportRequest($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'generateBrandMetricsReport'
     *
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     * @param  \AmazonAdvertisingApi\Model\BrandMetricsGenerateReportRequest $body Create request body to generate the Brand Metrics Report (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function generateBrandMetricsReportRequest($amazon_advertising_api_scope, $amazon_advertising_api_client_id, $body = null)
    {
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling generateBrandMetricsReport'
            );
        }
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling generateBrandMetricsReport'
            );
        }

        $resourcePath = '/insights/brandMetrics/report';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientID'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }


        // body params
        $_tempBody = null;
        if (isset($body)) {
            $_tempBody = $body;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.insightsBrandMetrics.v1+json', 'application/vnd.insightsBrandMetricsError.v1+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.insightsBrandMetrics.v1+json', 'application/vnd.insightsBrandMetricsError.v1+json'],
                ['application/vnd.insightsBrandMetrics.v1+json']
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getBrandMetricsReport
     *
     * Retrieve the status and the URL of the Brand Metrics Report being generated
     *
     * @param  string $report_id The report Id to be fetched (required)
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \AmazonAdvertisingApi\Model\BrandMetricsGetReportByIdResponse
     */
    public function getBrandMetricsReport($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
    {
        list($response) = $this->getBrandMetricsReportWithHttpInfo($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id);
        return $response;
    }

    /**
     * Operation getBrandMetricsReportWithHttpInfo
     *
     * Retrieve the status and the URL of the Brand Metrics Report being generated
     *
     * @param  string $report_id The report Id to be fetched (required)
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     *
     * @throws \AmazonAdvertisingApi\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \AmazonAdvertisingApi\Model\BrandMetricsGetReportByIdResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getBrandMetricsReportWithHttpInfo($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\BrandMetricsGetReportByIdResponse';
        $request = $this->getBrandMetricsReportRequest($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if (!in_array($returnType, ['string','integer','bool'])) {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsGetReportByIdResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 403:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 422:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 424:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 500:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\AmazonAdvertisingApi\Model\BrandMetricsError',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getBrandMetricsReportAsync
     *
     * Retrieve the status and the URL of the Brand Metrics Report being generated
     *
     * @param  string $report_id The report Id to be fetched (required)
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBrandMetricsReportAsync($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
    {
        return $this->getBrandMetricsReportAsyncWithHttpInfo($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getBrandMetricsReportAsyncWithHttpInfo
     *
     * Retrieve the status and the URL of the Brand Metrics Report being generated
     *
     * @param  string $report_id The report Id to be fetched (required)
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getBrandMetricsReportAsyncWithHttpInfo($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
    {
        $returnType = '\AmazonAdvertisingApi\Model\BrandMetricsGetReportByIdResponse';
        $request = $this->getBrandMetricsReportRequest($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getBrandMetricsReport'
     *
     * @param  string $report_id The report Id to be fetched (required)
     * @param  string $amazon_advertising_api_scope The profile Id, for example, 195213312458027. (required)
     * @param  string $amazon_advertising_api_client_id The client Id, for example, amzn1.application-oa2-client.8baa9caa3eac48eab89780e73ce03b19. (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getBrandMetricsReportRequest($report_id, $amazon_advertising_api_scope, $amazon_advertising_api_client_id)
    {
        // verify the required parameter 'report_id' is set
        if ($report_id === null || (is_array($report_id) && count($report_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $report_id when calling getBrandMetricsReport'
            );
        }
        // verify the required parameter 'amazon_advertising_api_scope' is set
        if ($amazon_advertising_api_scope === null || (is_array($amazon_advertising_api_scope) && count($amazon_advertising_api_scope) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_scope when calling getBrandMetricsReport'
            );
        }
        // verify the required parameter 'amazon_advertising_api_client_id' is set
        if ($amazon_advertising_api_client_id === null || (is_array($amazon_advertising_api_client_id) && count($amazon_advertising_api_client_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $amazon_advertising_api_client_id when calling getBrandMetricsReport'
            );
        }

        $resourcePath = '/insights/brandMetrics/report/{reportId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // header params
        if ($amazon_advertising_api_scope !== null) {
            $headerParams['Amazon-Advertising-API-Scope'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_scope);
        }
        // header params
        if ($amazon_advertising_api_client_id !== null) {
            $headerParams['Amazon-Advertising-API-ClientID'] = ObjectSerializer::toHeaderValue($amazon_advertising_api_client_id);
        }

        // path params
        if ($report_id !== null) {
            $resourcePath = str_replace(
                '{' . 'reportId' . '}',
                ObjectSerializer::toPathValue($report_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/vnd.insightsBrandMetrics.v1+json', 'application/vnd.insightsBrandMetricsError.v1+json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/vnd.insightsBrandMetrics.v1+json', 'application/vnd.insightsBrandMetricsError.v1+json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            // \stdClass has no __toString(), so we should encode it manually
            if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($httpBody);
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\Query::build($formParams);
            }
        }


        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\Query::build($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
